package org.mwiki.scala.bot.http

import dispatch.{Request, Http}

/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: Mar 28, 2010
 * Time: 10:24:17 PM
 * To change this template use File | Settings | File Templates.
 */

object MwRequest {
  val userAgent: String = "scala-mediawiki-bot/0.1 http://code.google.com/p/scala-mediawiki-bot/"
  val maxlag = 5

  val url = "http://uk.wikipedia.org/w/api.php"

  def getRequest() : Request =  {
    val http = new Http
    val request = new Request(url)
    request <:< Map("User-Agent" -> userAgent)
  }

  def getRequest(format: String) : Request =
    getRequest() <<? Map("format" -> "xml")

  def request(map: Map[String, String]) = {
    val request = MwRequest.getRequest("xml") <<? map
    val responseBody = Http(request as_str)
    responseBody.toString()
  }

}